﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class AddUpdateTypeCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            load_RecordStatus();


            if (Request.QueryString["id"] != null)
            {
                int iID = int.Parse(Request.QueryString["id"].ToString());
                load_Type_Category(iID);
            }
        }
    }

    public void load_Type_Category(int iID)
    {
        DataSet dsTypeCategory = BusLogic.TypeCategory.get_TYPE_CATEGORY(iID);

        if (dsTypeCategory.Tables[0].Rows.Count > 0)
        {
            txtName.Text = dsTypeCategory.Tables[0].Rows[0]["NAME"].ToString();
            txtDescription.Text = dsTypeCategory.Tables[0].Rows[0]["DESCRIPTION"].ToString();
            txtSort.Text = dsTypeCategory.Tables[0].Rows[0]["SORTED"].ToString();
            rdlRecordStatus.SelectedValue = dsTypeCategory.Tables[0].Rows[0]["RECORD_STATUS"].ToString();
        }
    }

    protected void lbtSave_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] == null)
        {
            BusLogic.TypeCategory.add_TYPE_CATEGORY(txtName.Text, txtDescription.Text, int.Parse(txtSort.Text), Boolean.Parse(rdlRecordStatus.SelectedValue));
        }
        else
        {
            int iID = int.Parse(Request.QueryString["id"].ToString());
            BusLogic.TypeCategory.update_TYPE_CATEGORY(iID, txtName.Text, txtDescription.Text, int.Parse(txtSort.Text), Boolean.Parse(rdlRecordStatus.SelectedValue));
        }

        Response.Redirect("TypeCategoryManager.aspx");
    }

    public void load_RecordStatus()
    {
        ListItem item = new ListItem();

        item.Value = "True";
        item.Text = "Công bố";
        item.Selected = true;
        rdlRecordStatus.Items.Add(item);

        item = new ListItem();
        item.Value = "False";
        item.Text = "Chờ";
        rdlRecordStatus.Items.Add(item);
    }
}
